home *** CD-ROM | disk | FTP | other *** search
/ SPACE 1 / SPACE - Library 1 - Volume 1.iso / program / 70 / examples / examples.arc / CONTROL.ST < prev    next >
Text File  |  1985-11-20  |  1KB  |  51 lines

  1. "
  2.     control the values produced by a generator
  3. "
  4. Class ControlGenerator :Generator
  5. | firstGenerator secondGenerator
  6.     currentFirst currentSecond
  7.     controlBlock computeBlock |
  8. [
  9.     initA: fGen b: sGen control: aBlock compute: anotherBlock
  10.         firstGenerator <- fGen.
  11.         secondGenerator <- sGen.
  12.         controlBlock <- aBlock.
  13.         computeBlock <- anotherBlock
  14.  
  15. |    first
  16.         currentFirst <- firstGenerator first.
  17.         currentSecond <- secondGenerator first.
  18.         (currentFirst isNil & currentSecond isNil) ifTrue: [^ nil].
  19.         ^ self controlGeneratorNext
  20.  
  21. |    next
  22.         ^ self controlGeneratorNext
  23.  
  24. |    controlGeneratorNext    | control returnedValue |
  25.         control <- 0.
  26.         [ control anyMask: 12] whileFalse: [
  27.             control <- controlBlock value: currentFirst
  28.                         value: currentSecond.
  29.             (control allMask: 64) ifTrue: [^nil].
  30.             (control allMask: 32) ifTrue:
  31.                 [currentFirst <- firstGenerator first].
  32.             (control allMask: 16) ifTrue:
  33.                 [currentSecond <- secondGenerator first].
  34.             (control allMask: 12)
  35.             ifTrue:
  36.                 [returnedValue <- computeBlock
  37.                 value: currentFirst value: currentSecond]
  38.             ifFalse: [
  39.              (control allMask: 8) ifTrue:
  40.                 [returnedValue <- computeBlock value: currentFirst].
  41.              (control allMask: 4) ifTrue:
  42.                 [returnedValue <- computeBlock value: currentSecond].
  43.              ].
  44.             (control allMask: 2) ifTrue:
  45.                 [currentFirst <- firstGenerator next].
  46.             (control allMask: 1) ifTrue:
  47.                 [currentSecond <- secondGenerator next].
  48.             ].
  49.         ^ returnedValue
  50. ]
  51.